package cn.qn.dto;

import java.io.Serializable;

/**
 * Project ID：600YF17065
 * Resume：rest请求返回dto<br/>
 *
 * @version 
 * @see
 */
public class ResponseDTO<T> implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3808589674007701010L;
	
	public static final int SUCCESS_CODE = 0;
    public static final int ERROR_CODE = 1;

    private Integer code;
    private String message;
    private T data;
    
    public ResponseDTO() {
    }


    public ResponseDTO(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseDTO(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseDTO<T> success(T data) {
		ResponseDTO<T> response = new ResponseDTO<T>();
        response.setCode(SUCCESS_CODE);
        response.setData(data);
        return response;
    }
    public static <T> ResponseDTO<T> success(T data,String message) {
    	ResponseDTO<T> response = new ResponseDTO<T>();
    	response.setCode(SUCCESS_CODE);
    	response.setData(data);
    	response.setMessage(message);
    	return response;
    }

    public static <T> ResponseDTO<T> success() {
    	ResponseDTO<T> response = new ResponseDTO<T>();
        response.setCode(SUCCESS_CODE);
        return response;
    }

    public static <T> ResponseDTO<T> error(String errorMessage) {
        return new ResponseDTO<T>(ERROR_CODE, errorMessage);
    }

    public static <T> ResponseDTO<T> error(int errCode, String errorMessage) {
        return new ResponseDTO<T>(errCode, errorMessage);
    }
	/**
	 * code.
	 * @return the code
	 */
	public int getCode() {
		return code;
	}
	/**
	 * code.
	 * @param code the code to set
	 */
	public void setCode(int code) {
		this.code = code;
	}
	/**
	 * message.
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}
	/**
	 * message.
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
	/**
	 * data.
	 * @return the data
	 */
	public T getData() {
		return data;
	}
	/**
	 * data.
	 * @param data the data to set
	 */
	public void setData(T data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "ResponseDTO{" +
				"code=" + code +
				", message='" + message + '\'' +
				", data=" + data +
				'}';
	}
}
